<template>
  <view v-if="list.order">
    <view
      v-if="list.order.order_substate == 1 || (list.order.order_substate == 2 && list.order.consult_id != 0)"
      @click="tohear(list.order.order_substate == 1)"
      class="flex align-center bg-white padding"
      style="position: fixed; width: 100%; background: #fff; z-index: 999"
    >
      <view class="flex-sub">
        <view class="col-333">
          {{ list.order.order_substate == 1 ? '请及时填写患者信息' : list.order.order_substate == 2 && list.order.consult_id != 0 ? '请及时填写问诊单' : '' }}
        </view>
        <view class="col-666 margin-top-sm font24">
          缺少{{
            list.order.order_substate == 1 ? '请及时填写患者信息' : list.order.order_substate == 2 && list.order.consult_id != 0 ? '患者信息' : '问诊单'
          }}医生无法正确了解您的身体状况
        </view>
      </view>
      <text class="cuIcon-right"></text>
    </view>
    <view class="padding" style="padding-bottom: 120rpx" id="box1">
      <view class="" v-for="(item, index) in msglist" :key="index">
        <!-- 时间日期 -->
        <view class="text-center col-999 font24 padding-tb-sm" v-if="item.type == 99">
          {{ item.content }}
        </view>
        <!-- 赠送提问 -->
        <view class="text-center col-999 font24 padding-tb-sm" v-if="item.type == 202">
          {{ item.content }},
          <text style="color: #63b6ff" @click="toyqtw">点此可继续与医生沟通病情</text>
        </view>
        <!-- 我的发送信息 -->
        <view class="flex padding-tb-sm" v-if="item.type == 1 && item.sender == 1">
          <view class="flex-sub"></view>
          <view class="bg-white" style="max-width: 420rpx; padding: 23rpx 22rpx; border-radius: 16rpx">
            {{ item.content }}
          </view>
          <view class="" style="padding-left: 24rpx">
            <image :src="item.avatar" style="width: 80rpx; height: 80rpx; border-radius: 50%" mode="aspectFill"></image>
          </view>
        </view>
        <!-- 我的发送图片 -->
        <view class="flex padding-tb-sm" v-if="item.type == 2 && item.sender == 1">
          <view class="flex-sub"></view>
          <view class="bg-white" style="max-width: 420rpx; padding: 23rpx 22rpx; border-radius: 16rpx">
            <image :src="item.content" @click="util.seeimg([item.content], 0)" style="width: 180rpx; height: 180rpx" mode="aspectFill"></image>
          </view>
          <view class="" style="padding-left: 24rpx">
            <image :src="item.avatar" style="width: 80rpx; height: 80rpx; border-radius: 50%" mode="aspectFill"></image>
          </view>
        </view>
        <!-- 同意书 -->
        <view class="flex align-center justify-center padding-tb-sm" v-if="item.type == 98">
          <view class="font24 text-center col-999" style="width: 551rpx">
            根据国互联网诊疗相关规定，请仔细阅读
            <text style="color: #63b6ff" @click="util.urlTo('/pages/index/xieyi?type=3')">《互联网诊疗风险告知及知情同意书》</text>
          </view>
        </view>
        <!-- 医生发送信息 -->
        <view class="flex padding-tb-sm" v-if="item.type == 1 && item.sender == 0">
          <view class="" style="padding-right: 24rpx">
            <image :src="item.avatar" style="width: 80rpx; height: 80rpx; border-radius: 50%" mode="aspectFill"></image>
          </view>
          <view class="bg-white" style="max-width: 420rpx; padding: 23rpx 22rpx; border-radius: 16rpx">
            {{ item.content }}
          </view>
          <view class="flex-sub"></view>
        </view>
        <!-- 医生发送图片 -->
        <view class="flex padding-tb-sm" v-if="item.type == 2 && item.sender == 0">
          <view class="" style="padding-right: 24rpx">
            <image :src="item.avatar" style="width: 80rpx; height: 80rpx; border-radius: 50%" mode="aspectFill"></image>
          </view>
          <view class="bg-white" style="max-width: 420rpx; padding: 23rpx 22rpx; border-radius: 16rpx">
            <image :src="item.content" @click="util.seeimg([item.content], 0)" style="width: 180rpx; height: 180rpx" mode="aspectFill"></image>
          </view>
          <view class="flex-sub"></view>
        </view>
        <!-- 我的视频 -->
        <view class="flex padding-tb-sm" v-if="item.type == 4 && item.sender == 1">
          <view class="flex-sub"></view>
          <view class="bg-white flex align-center" style="max-width: 420rpx; padding: 23rpx 22rpx; border-radius: 16rpx">
            <view class="">
              {{ item.content }}
            </view>
            <image src="https://wenzhen.fuerle168.com/static/home/spicon.png" style="width: 33rpx; height: 24rpx; margin-left: 16rpx" mode=""></image>
          </view>
          <view class="" style="padding-left: 24rpx">
            <image :src="item.avatar" style="width: 80rpx; height: 80rpx; border-radius: 50%" mode="aspectFill"></image>
          </view>
        </view>
        <!-- 医生视频 -->
        <view class="flex padding-tb-sm" v-if="item.type == 4 && item.sender == 0">
          <view class="" style="padding-right: 24rpx">
            <image :src="item.avatar" style="width: 80rpx; height: 80rpx; border-radius: 50%" mode="aspectFill"></image>
          </view>
          <view class="bg-white flex align-center" style="max-width: 420rpx; padding: 23rpx 22rpx; border-radius: 16rpx">
            <image src="https://wenzhen.fuerle168.com/static/home/fspicon.png" style="width: 33rpx; height: 24rpx; margin-right: 16rpx" mode=""></image>
            <view class="">
              {{ item.content }}
            </view>
          </view>
          <view class="flex-sub"></view>
        </view>
        <!-- 我的电话 -->
        <view class="flex padding-tb-sm" v-if="item.type == 3 && item.sender == 1">
          <view class="flex-sub"></view>
          <view class="bg-white flex align-center" style="max-width: 420rpx; padding: 23rpx 22rpx; border-radius: 16rpx">
            <view class="">聊天时长：11:25</view>
            <image src="https://wenzhen.fuerle168.com/static/home/phoneicon.png" style="width: 36rpx; height: 18rpx; margin-left: 16rpx" mode=""></image>
          </view>
          <view class="" style="padding-left: 24rpx">
            <image :src="item.avatar" style="width: 80rpx; height: 80rpx; border-radius: 50%" mode="aspectFill"></image>
          </view>
        </view>
        <!-- 医生电话 -->
        <view class="flex padding-tb-sm" v-if="item.type == 3 && item.sender == 0">
          <view class="" style="padding-right: 24rpx">
            <image :src="item.avatar" style="width: 80rpx; height: 80rpx; border-radius: 50%" mode="aspectFill"></image>
          </view>
          <view class="bg-white flex align-center" style="max-width: 420rpx; padding: 23rpx 22rpx; border-radius: 16rpx">
            <image src="https://wenzhen.fuerle168.com/static/home/phoneicon.png" style="width: 36rpx; height: 18rpx; margin-right: 16rpx" mode=""></image>
            <view class="">聊天时长：11:25</view>
          </view>
          <view class="flex-sub"></view>
        </view>
        <!-- 评价医生 -->
        <view class="flex padding-tb-sm" v-if="item.type == 203">
          <view class="" style="padding-right: 24rpx">
            <image :src="item.avatar" style="width: 80rpx; height: 80rpx; border-radius: 50%" mode="aspectFill"></image>
          </view>
          <view @click="toevaluation(item)" class="bg-white" style="max-width: 420rpx; padding: 23rpx 22rpx; border-radius: 16rpx">
            <view class="col-333 text-bold">评价医生</view>
            <view class="font26 margin-top-sm" style="color: #888; padding-right: 116rpx">欢迎对服务做出评价</view>
          </view>
          <view class="flex-sub"></view>
        </view>
        <!-- 您当前的免费提问次数已用完 -->
        <view class="flex align-center justify-center padding-tb-sm" v-if="item.type == 98 && gettype(item.content) == 12">
          <view class="bg-white text-center padding-bottom" style="width: 456rpx; border-radius: 16rpx">
            <view class="col-333" style="padding: 57rpx 0rpx 55rpx">您当前的免费提问次数已用完</view>
            <view class="flex align-center justify-center">
              <view @click="util.urlTo('questions')" class="btnbg" style="width: 284rpx; height: 80rpx">继续提问</view>
            </view>
          </view>
        </view>
        <!-- 患者姓名 -->
        <view class="margin-tb-sm bg-white radius20" style="padding: 36rpx 28rpx" v-if="item.type == 104">
          <view class="">
            <view class="col-333 font30 text-bold">患者姓名</view>
            <view class="font24 col-666" style="margin-top: 23rpx">
              {{ gettype(item.content).patient_age }}岁 · {{ gettype(item.content).patient_city }}省 ·{{ gettype(item.content).patient_height }}cm ·
              {{ gettype(item.content).patient_weight }}kg
            </view>
          </view>
          <view class="" style="margin-top: 30rpx">
            <view class="padding-sm margin-bottom" style="border: solid 1rpx #e8e8e8; border-radius: 10rpx">
              <view class="col-333">过敏历史</view>
              <view class="font26 margin-top-sm" style="color: #888; line-height: 42rpx">
                {{ gettype(item.content).illness_one }}
              </view>
            </view>
            <view class="padding-sm margin-bottom" style="border: solid 1rpx #e8e8e8; border-radius: 10rpx">
              <view class="col-333">既往病史</view>
              <view class="font26 margin-top-sm" style="color: #888; line-height: 42rpx">
                {{ gettype(item.content).illness_two }}
              </view>
            </view>
            <view class="padding-sm margin-bottom" style="border: solid 1rpx #e8e8e8; border-radius: 10rpx">
              <view class="col-333">患者自述</view>
              <view class="font26 margin-top-sm" style="color: #888; line-height: 42rpx">
                {{ gettype(item.content).illness_three }}
              </view>
            </view>
          </view>
          <view class="col-333">其他资料</view>
          <view class="margin-top-sm">
            <image
              :src="img + item1"
              v-for="(item1, index) in item.content.illness_image"
              :key="index"
              style="width: 190rpx; height: 190rpx; border-radius: 16rpx; margin-right: 14rpx; margin-bottom: 14rpx"
              mode=""
              @tap="util.seeimg([img + item1], index)"
            ></image>
          </view>
          <view class="flex align-center" style="margin-top: 39rpx">
            <view class="flex-sub col-333">问诊单信息</view>
            <view class="font30" style="color: #0087fe">已提交</view>
          </view>
        </view>
        <!-- 问诊单 -->
        <view @click="util.urlTo('Consultation?orderid=' + this.list.order.order_id)" class="bg-white radius20 margin-tb-sm" v-if="item.type == 106">
          <view class="" style="padding: 34rpx 28rpx; border-bottom: solid 1rpx #eeeeee">
            <view class="col-333">
              {{ item.content[0] }}的问诊单
              <text class="font26" style="background-color: #e6f2fe; border-radius: 8rpx; color: #0087fe; padding: 8rpx 13rpx; margin-left: 19rpx">已提交</text>
            </view>
            <view class="font24 col-999" style="margin-top: 15rpx">
              {{ item.content[1] }}
            </view>
          </view>
          <view class="" style="padding: 34rpx 28rpx">
            <view class="col-333" style="padding-bottom: 32rpx; border-bottom: solid 1rpx #eeeeee">
              患者：{{ item.content[0] }}（{{ item.content[2] == 1 ? '男' : '女' }} · {{ item.content[3] }}岁）
            </view>
            <view class="col-999" style="padding-top: 32rpx">
              {{ item.content[4] }}
            </view>
          </view>
        </view>
        <!-- 诊疗方案 -->
        <view class="bg-white radius20 margin-tb-sm" v-if="item.type == 117">
          <view class="" style="padding: 34rpx 28rpx; border-bottom: solid 1rpx #eeeeee">
            <view class="col-333">
              {{ item.content[0] }}
            </view>
            <view class="font24 col-999" style="margin-top: 15rpx">
              {{ item.content[1] }}
            </view>
          </view>
          <view class="" style="padding: 34rpx 28rpx">
            <view class="col-333" style="padding-bottom: 32rpx; border-bottom: solid 1rpx #eeeeee">
              {{ item.content[2] }}
            </view>
            <view class="col-333" style="padding: 32rpx 0rpx; border-bottom: solid 1rpx #eeeeee">
              {{ item.content[3] }}
            </view>
            <view class="col-999" style="padding-top: 32rpx">
              {{ item.content[4] }}
              <view class="flex align-center justify-center" style="margin-top: 33rpx">
                <view @click="look(item)" class="btnbg font30" style="width: 500rpx; height: 80rpx">点此查看治疗方案</view>
              </view>
            </view>
          </view>
        </view>
        <!-- 请对本次问诊做出评价 -->
        <view class="margin-tb-sm flex align-center justify-center" style="margin-top: 70rpx" v-if="item.type == 204">
          <view class="bg-white text-center padding-bottom" style="width: 420rpx; border-radius: 16rpx">
            <image :src="item.avatar" style="width: 104rpx; height: 104rpx; border-radius: 50%; margin-top: -43rpx" mode="aspectFill"></image>
            <view class="col-333" style="padding: 31rpx 0rpx 34rpx">
              {{ item.content }}
            </view>
            <view class="flex align-center justify-center">
              <view
                @click="util.urlTo('/chat/EvaluationDoctor/EvaluationDoctor?id=' + id + '&orderid=' + list.order.order_id)"
                class="btnbg"
                style="width: 284rpx; height: 80rpx"
                v-if="list.order.is_evaluate == 0"
              >
                立即评价
              </view>
              <view @click="util.showToast('已评价')" class="btnbg" style="width: 284rpx; height: 80rpx; background: #666; color: #fff" v-if="list.order.is_evaluate == 1">
                已评价
              </view>
            </view>
          </view>
        </view>
        <!-- 邀请慢病患者 -->
        <view class="margin-tb-sm flex align-center justify-center" style="margin-top: 70rpx" v-if="item.type == 205">
          <view class="bg-white text-center padding-bottom" style="width: 420rpx; border-radius: 16rpx">
            <image :src="item.avatar" style="width: 104rpx; height: 104rpx; border-radius: 50%; margin-top: -43rpx" mode="aspectFill"></image>
            <view class="col-333" style="padding: 31rpx 0rpx 34rpx">
              {{ item.content }}
            </view>
            <view class="flex align-center" style="justify-content: space-around" v-if="item.is_agree == 0">
              <view @click="refuse(item.id)" class="btnbg" style="width: 170rpx; height: 80rpx; background: #fff; color: #666; border: 1rpx solid #666">拒绝</view>
              <view @click="agree(item.id)" class="btnbg" style="width: 170rpx; height: 80rpx">同意</view>
            </view>
            <view class="" v-if="item.is_agree != 0" style="text-align: center; color: red; font-size: 28rpx">
              {{ item.is_agree == 2 ? '已拒绝' : '已同意' }}
            </view>
          </view>
        </view>
      </view>
      <view class="" v-if="list.order.order_status == 3">
        <!-- 图文问诊 -->
        <view class="margin-tb-sm flex align-center bg-white radius20" style="padding: 37rpx 40rpx" v-for="(i, k) in info.inquiry">
          <view class="flex-sub">
            <view class="font34 col-333">
              {{ i.type_text }}
            </view>
            <view class="font26 col-999 margin-top-sm">
              {{
                i.type == 1
                  ? '自由图文交流，开方调药'
                  : i.type == 2
                  ? '直接与医生电话，开方调药'
                  : i.type == 3
                  ? '与医生视频交流，开方调药'
                  : i.type == 5
                  ? '直接预约医生'
                  : '简单问题找医生快速回复'
              }}
            </view>
          </view>
          <view @click="sub_wen(i.type)" class="font30" style="border: solid 1rpx #0087fe; color: #0087fe; padding: 9rpx 21rpx; border-radius: 52rpx">点此问诊</view>
        </view>
        <!-- 语音问诊 -->
        <!-- <view class="margin-tb-sm flex align-center bg-white radius20" style="padding: 37rpx 40rpx;">
					<view class="flex-sub">
						<view class="font34 col-333">
							语音问诊
						</view>
						<view class="font26 col-999 margin-top-sm">
							直接与医生电话，开方调药
						</view>
					</view>
					<view @click="util.urlTo('/pages/index/fwpay?id='+id + '&type=1')" class="font30"
						style="border: solid 1rpx #0087FE;color: #0087FE;padding: 9rpx 21rpx;border-radius: 52rpx;">
						点此问诊
					</view>
				</view> -->
        <!-- 视频问诊 -->
        <!-- <view class="margin-tb-sm flex align-center bg-white radius20" style="padding: 37rpx 40rpx;">
					<view class="flex-sub">
						<view class="font34 col-333">
							视频问诊
						</view>
						<view class="font26 col-999 margin-top-sm">
							与医生视频交流，开方调药
						</view>
					</view>
					<view @click="util.urlTo('/pages/index/fwpay?id='+id + '&type=1')" class="font30"
						style="border: solid 1rpx #0087FE;color: #0087FE;padding: 9rpx 21rpx;border-radius: 52rpx;">
						点此问诊
					</view>
				</view> -->
        <!-- 视频问诊 -->
        <!-- <view class="margin-tb-sm flex align-center bg-white radius20" style="padding: 37rpx 40rpx;">
					<view class="flex-sub">
						<view class="font34 col-333">
							多次问答
						</view>
						<view class="font26 col-999 margin-top-sm">
							直接预约医生
						</view>
					</view>
					<view @click="util.urlTo('/pages/index/fwpay?id='+id + '&type=2')" class="font30"
						style="border: solid 1rpx #0087FE;color: #0087FE;padding: 9rpx 21rpx;border-radius: 52rpx;">
						点此问诊
					</view>
				</view> -->
        <!-- 健康咨询 -->
        <!-- <view class="margin-tb-sm flex align-center bg-white radius20" style="padding: 37rpx 40rpx;">
					<view class="flex-sub">
						<view class="font34 col-333">
							健康咨询
						</view>
						<view class="font26 col-999 margin-top-sm">
							简单问题找医生快速回复
						</view>
					</view>
					<view @click="util.urlTo('/pages/index/fwpay?id='+id + '&type=1')" class="font30"
						style="border: solid 1rpx #0087FE;color: #0087FE;padding: 9rpx 21rpx;border-radius: 52rpx;">
						点此问诊
					</view>
				</view> -->
      </view>
    </view>

    <view class="foot-box bg-white" style="padding: 12rpx 38rpx; padding-bottom: 20rpx">
      <view
        class="flex align-center"
        v-if="
          list.order.order_type == 1 ||
          list.order.order_type == 4 ||
          list.order.order_type == 5 ||
          list.order.order_type == 7 ||
          list.order.order_type == 6 ||
          list.order.order_substate == 6
        "
      >
        <text @click="sendtp" class="cuIcon-pic font44"></text>
        <view class="flex-sub" style="background-color: #f8f8f8; margin: 0rpx 26rpx 0rpx 31rpx; padding: 24rpx 35rpx; border-radius: 37rpx">
          <input type="text" v-model="content" placeholder="输入聊天内容" placeholder-class="placestype" />
        </view>
        <view @click="sendtext(1)" class="font26" style="color: #0087fe">发送</view>
      </view>
      <!--  v-if="list.order.order_type == 2" -->
      <view
        v-if="list.order.order_type == 2 && list.order.order_substate != 6"
        @click="boda"
        class="font26 flex align-center justify-center col-999"
        style="background-color: #f8f8f8; width: 694rpx; height: 75rpx; border-radius: 37rpx"
      >
        拨打语音
      </view>
      <view
        v-if="list.order.order_type == 3 && list.order.order_substate != 6"
        @click="boda"
        class="font26 flex align-center justify-center col-999"
        style="background-color: #f8f8f8; width: 694rpx; height: 75rpx; border-radius: 37rpx"
      >
        拨打视频
      </view>
      <!-- <view class="" @tap="aa" style="height: 50rpx">测试拨打视频</view> -->
    </view>
    <u-popup v-model="show" mode="center" width="400" height="300" border-radius="20">
      <view style="height: 200rpx; width: 100%; text-align: center; line-height: 200rpx">前往等待医生视频通话</view>
      <view style="display: flex; align-items: center; justify-content: space-between; width: 100%; height: 100rpx">
        <view style="font-size: 30rpx; color: #000000; text-align: center; line-height: 100rpx; width: 50%; height: 100rpx" @click="show = false">取消</view>
        <view style="font-size: 30rpx; color: #000000; text-align: center; line-height: 100rpx; width: 50%; height: 100rpx" @click="gophoneview">确定</view>
      </view>
    </u-popup>
  </view>
</template>

<script>
export default {
  data() {
    return {
      show: null,
      id: '',
      page: 1,
      list: [],
      msglist: [],
      content: '',
      img: this.util.api.img,
      msgs: null,
      background: {
        background: '#F8F8F8'
      },
      patient_id: null,
      info: {}
    };
  },
  onLoad(op) {
    console.log(this.util.msg);
    this.msgs = this.util.msg;
    op.id ? (this.id = op.id) : '';
    console.log('--------=--=-', this.id);
    op.patient_id ? (this.patient_id = op.patient_id) : '';
    if (op.type == 3) {
      this.show = true;
    }
  },
  onShow() {
    // if(this.id){
    // 	this.getlist()
    // }
    this.detail();
  },
  onPageScroll(e) {
    if (e.scrollTop == 0) {
      this.page++;
      this.getlist(2);
    }
  },
  watch: {
    msgs: {
      handler(newName, oldName) {
        console.log('进不来？');
        this.page = 1;
        this.msglist = [];
        this.getlist(1);
      },
      deep: true
    }
  },
  methods: {
    //前往分包
    gophoneview() {
      uni.navigateTo({
        url: '/TUICallKit/pages/call'
      });
    },
    // init() {
    //   this.api({
    //     url: '/api/chat/getSign',
    //     method: 'post'
    //   }).then((data) => {
    //     this.$nextTick(() => {
    //       TUICallKitServer.init({
    //         sdkAppID: 1600052101,
    //         userID: String(uni.getStorageSync('user_info').id),
    //         userSig: data.data
    //       });
    //     });
    //   });
    // },
    aa() {
      uni.reLaunch({
        url: '/TUICallKit/pages/call'
      });
    },
    sub_wen(e) {
      if (e == 5) {
        this.util.urlTo('/fwpay/fwpay/fwpay?id=' + this.id + '&type=2');
      } else {
        this.util.urlTo('/fwpay/fwpay/fwpay?id=' + this.id + '&type=1' + '&u_type=' + e);
      }
    },
    detail() {
      this.api({
        url: '/api/doctor/details',
        method: 'post',
        data: {
          doctor_id: this.id
        }
      }).then((res) => {
        this.info = res.data;
      });
    },
    boda() {
      uni.showToast({
        title: '请耐心等待医生来电',
        icon: 'none'
      });
    },
    look(e) {
      console.log(e);
      if (e.is_pay == 0) {
        this.util.urlTo('/news/scheme/scheme?id=' + e.content[5] + '&open=true');
      } else {
        uni.navigateTo({
          url: '/user/orderdetail/orderdetail?id=' + e.order_serve_id
        });
      }
    },
    agree(e) {
      this.api({
        url: '/api/patient/addSlowPatientsList',
        method: 'post',
        data: {
          id: e,
          doctor_id: this.id,
          patient_id: this.patient_id
        }
      }).then((res) => {
        uni.showToast({
          title: res.msg,
          icon: 'none'
        });
        this.getlist(1);
      });
    },
    refuse(e) {
      this.api({
        url: '/api/patient/refuseSlowPatients',
        method: 'post',
        data: {
          id: e,
          doctor_id: this.id,
          patient_id: this.patient_id
        }
      }).then((res) => {
        uni.showToast({
          title: res.msg,
          icon: 'none'
        });
        this.getlist(1);
      });
    },
    tohear(e) {
      e
        ? this.util.urlTo('/chat/patientinfo/patientinfo?id=' + this.id + '&orderid=' + this.list.order.order_id + '&info=' + JSON.stringify(this.list.patient))
        : this.util.urlTo('/chat/Consultation/Consultation?id=' + this.list.order.consult_id + '&orderid=' + this.list.order.order_id);
    },
    toevaluation(item) {
      if (this.list.order.is_evaluate == 1) {
        this.util.showToast('您已评价过');
        return false;
      }
      this.util.urlTo('/chat/EvaluationDoctor/EvaluationDoctor?id=' + this.id + '&orderid=' + item.content);
    },
    toyqtw() {
      let data = this.list.patient;
      data.give_number = this.list.order.give_number;
      data.order_id = this.list.order.order_id;
      this.util.urlTo('/chat/questions/questions?info=' + JSON.stringify(data));
    },
    getlist(e) {
      let that = this;
      // this.util.request('chat/getUserRecord',{
      // 	page: this.page,
      // 	doctor_id: this.id
      // },'post').then(res => {
      // 	this.list = res;
      // 	this.msglist = res.log.concat(this.msglist)
      // 	if(this.page == 1){
      // 		that.$nextTick(()=>{
      // 			const query = uni.createSelectorQuery();
      // 			query.select('#box1').boundingClientRect(rect => {}).exec((e)=>{
      // 				uni.pageScrollTo({
      // 					duration: 0,
      // 					scrollTop: e[0].bottom
      // 				})
      // 			})
      // 		})
      // 	}
      // })
      this.api({
        url: '/api/chat/getUserRecord',
        method: 'post',
        data: {
          page: this.page,
          doctor_id: this.id,
          patient_id: this.patient_id
        }
      }).then((res) => {
        this.list = res.data;
        if (e == 2) {
          this.msglist = res.data.log.concat(this.msglist);
        } else {
          this.msglist = res.data.log;
        }

        // if(this.page == 1){
        that.$nextTick(() => {
          const query = uni.createSelectorQuery();
          query
            .select('#box1')
            .boundingClientRect((rect) => {})
            .exec((e) => {
              // console.log(e[0].bottom,'距离')
              uni.pageScrollTo({
                duration: 0,
                scrollTop: 9999999999999
              });
            });
        });
        // }
      });
    },
    getunicode(e) {
      var str = e; // "站长 "
      str = encodeURIComponent(str);
      return str;
    },
    gettype(e) {
      // let item = eval('(' + e + ')').type;
      // let item = e.slice(0,e.length);
      // console.log(e.content)
      return e;
    },
    sendtp() {
      let that = this;
      uni.chooseImage({
        count: 1,
        success(res) {
          console.log(res);
          that.util.upload(res.tempFilePaths[0]).then((res1) => {
            that.sendtext(2, res1.fullurl);
          });
        }
      });
    },
    sendtext(e, v) {
      if (!v && !this.content) {
        this.util.showToast('请输入要发送的内容');
        return false;
      }
      // // 指定消息发送的目标会话
      // const conversation = {
      //   // targetId
      //   targetId: JSON.stringify(this.list.uid),
      //   // 会话类型：RongIMLib.ConversationType.PRIVATE | RongIMLib.ConversationType.GROUP
      //   conversationType: this.RongIMLib.ConversationType.PRIVATE
      // };

      // // 构建文本消息
      // const message = new this.RongIMLib.TextMessage({ content: 'message content' })

      // // 发送消息
      // this.RongIMLib.sendMessage(conversation, message).then(({ code, data }) => {
      //   if (code === 0) {
      //     console.log('消息发送成功：', data)

      this.api({
        url: '/api/chat/send',
        method: 'post',
        data: {
          order_id: this.list.order.order_id,
          touid: this.list.touid,
          type: e,
          content: v ? v : this.content,
          patient_id: this.patient_id
        }
      }).then((res) => {
        this.content = '';

        this.$nextTick(() => {
          const query = uni.createSelectorQuery();
          query
            .select('#box1')
            .boundingClientRect((rect) => {})
            .exec((e) => {
              uni.pageScrollTo({
                duration: 0,
                scrollTop: 9999999999999
              });
            });
        });
        this.page = 1;
        this.getlist(1);
      });
    }
  }
};
</script>

<style>
page {
  background-color: #f8f8f8;
}
</style>
